/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Bean.RoleOfEmployeeBean;
import Utility.DBProcess;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Vietlt
 */
public class RoleOfEmployeeDAO {
    public static void main(String[] args) {
        RoleOfEmployeeBean bean=new RoleOfEmployeeDAO().LoadAllRoleById(1);
        System.out.println(""+bean.getRoleName());
        System.out.println(""+bean.getEmployeeID());
    }
     public List<RoleOfEmployeeBean> LoadAllRoleOfEmployee() {
        List<RoleOfEmployeeBean> list = new ArrayList<RoleOfEmployeeBean>();
        Connection conn = null;
        CallableStatement stm = null;
        ResultSet rs = null;
        conn = DBProcess.getConnection();
        try {
            stm = conn.prepareCall("{ call RoleOfEmployee_getall}");
            rs = stm.executeQuery();
            while (rs.next()) {
                RoleOfEmployeeBean roleB = new RoleOfEmployeeBean();
                roleB.setEmployeeID(rs.getInt("EmployeeID"));
                roleB.setRoleName(rs.getString("RoleName"));
                list.add(roleB);
                if (list.isEmpty()) {
                    String err = "List empty !!!";
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(RoleDAO.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            DBProcess.closeResultSet(rs);
            DBProcess.closeStatement(stm);
            DBProcess.closeConnection(conn);
        }
        return list;
    }

    public RoleOfEmployeeBean LoadAllRoleById(int EmployeeID) {
        Connection conn = null;
        CallableStatement stm = null;
        ResultSet rs = null;
        conn = DBProcess.getConnection();
        RoleOfEmployeeBean roleB = new RoleOfEmployeeBean();
        try {
            stm = conn.prepareCall("{ call RoleOfEmployee_get (?)}");
            stm.setInt(1, EmployeeID);
            rs = stm.executeQuery();
            while (rs.next()) {
                roleB.setRoleName(rs.getString("RoleName"));
            }
        } catch (Exception ex) {
            Logger.getLogger(ApplicantDAO.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            DBProcess.closeResultSet(rs);
            DBProcess.closeStatement(stm);
            DBProcess.closeConnection(conn);
        }
        return roleB;
    }

}
